package com.ts.manage.cms.client.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String EXCHANGE_ROUTING = "ex_cmspage_post";
    public static final String QUEUE_BEAN_NAME = "queue_cmspagePost";
    public static final String ROUTING_EMAIL = "routing.#.email.#";

    @Value("${ts.mq.queue}")
    private String queueName;

    @Value("${ts.mq.routingKey}")
    private String routingKey;


    @Bean(EXCHANGE_ROUTING)
    public Exchange getExchange() {
        return ExchangeBuilder.directExchange(EXCHANGE_ROUTING).durable(true).build();
    }

    //Queue queue = new Queue(QUEUE_EMAIL);
    @Bean(QUEUE_BEAN_NAME)
    public Queue getQueueEmail() {
        Queue queue = new Queue(queueName);
        return queue;
    }

    @Bean
    public Binding binding_email(@Qualifier(QUEUE_BEAN_NAME) Queue queue, @Qualifier(EXCHANGE_ROUTING) Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(routingKey).noargs();
    }


}
